home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / VideoToolbox.h < prev    next >
Encoding:
Text File  |  1997-07-31  |  51.1 KB  |  1,445 lines  |  [TEXT/CWIE]

  1. /*
  2. VideoToolbox.h
  3. This file contains the necessary prototypes for use of all the VideoToolbox
  4. files except Luminance.c, which has its own header file, Luminance.h, and
  5. GDInfo.c and GDTestClut.c, which use GDInfo.h.
  6.  
  7. Precompilation of this header, producing VideoToolbox????.pre, 
  8. will reduce your compilation time tenfold. See VideoToolbox.pch (if you're
  9. using Metrowerks CodeWarrior) or VideoToolbox.c (any other compiler) for 
  10. instructions.
  11.  
  12. My convention is to assign different names to the precompiled header depending
  13. on the compile-time options: use of ppc/68k, 68881, and size of int.
  14.  
  15. The precompilation depends on the sizeof(double) and sizeof(int)
  16. because most functions use or return such values and the external interface must
  17. allow the appropriate amount of space. THINK C supports a 12-byte "universal"
  18. format double that works well both with the 68881 fpu (which uses the top two
  19. bytes and the bottom 8 bytes) and with SANE (which uses the bottom 10 bytes).
  20. Thus in THINK C it is easy to mix modules compiled with (e.g. your code) and
  21. without (e.g. the ANSI library) the 68881 option. Unfortunately that excellent
  22. feature is unique to THINK C. In MPW and CodeWarrior C you must use 10-byte
  23. doubles when you use SANE (i.e. don't use the 68881 fpu), so when you use these
  24. compilers you'll need separate pre-compiled headers, with and without the 68881
  25. option, if you want to compile for each environment: to use the 68881 fpu, or
  26. run on machines that lack it.
  27.  
  28. Metrowerks CodeWarrior project names end in ".µ", and indicate which cpu they
  29. support by "68k" or "ppc". THINK C projects support only the 68k and have names
  30. ending in ".π".
  31.  
  32. My naming convention for pre-compiled headers indicates the size of int, "2i" or
  33. "4i", and, if the 68881 is required, "881". Metrowerks pre-compiled headers
  34. indicate which cpu they support by "68k" or "ppc"; THINK C supports only the
  35. 68k. The THINK C pre-compiled header that I use is "VideoToolbox.pre", which
  36. uses 2-byte ints and "universal" 12-byte doubles that work with or without the
  37. 68881. (The THINK C ANSI library requires 2-byte ints.) The Metrowerks
  38. CodeWarrior C pre-compiled headers that I use are called,
  39. "VideoToolbox.68k.4i.pre", "VideoToolbox.68k.4i.881.pre", and
  40. "VideoToolbox.ppc.pre".
  41.  
  42. As of June 14, 1995, the VideoToolbox #includes <assert.h>, or, if MATLAB
  43. is true, defines a MATLAB-compatible version of assert(). If your source file
  44. #includes <assert.h> then it will be included again, undoing the work
  45. done here, including the MATLAB compatibility. For that reason you should NOT
  46. #include <assert.h> in your source files.
  47.  
  48. MAC_C:
  49.  
  50. Defining the symbol MAC_C as 0 before this file is compiled will leave only the 
  51. stuff that is written in pure Standard C, which will work on any computer.
  52.  
  53. The Apple Macintosh header files use some extensions to C that are not part of
  54. Standard C, e.g. "pascal", "short double", enums larger than ints, and function
  55. prototypes that specify absolute addresses. These keywords and constructions
  56. cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
  57. only on Macintosh C compilers that incorporate these extensions, and is false
  58. otherwise. The MAC_C symbol is used to prevent inclusion of all the
  59. Macintosh-dependent header files and prototypes when the compiler doesn't
  60. support them. However, lacking any general test for these extensions, a test
  61. must be added, below, for each new compiler. At present we test for Symantec C
  62. THINK C, Apple MPW C, and Metrowerks CodeWarrior C.
  63.  
  64. MATLAB:
  65.  
  66. If you want to use the VideoToolbox from within MATLAB then you'll be happy
  67. to know that all the work's been done for you. Get yourself a copy of the 
  68. Psychophysics Toolbox:
  69. <http://www.psych.ucsb.edu/~brainard/Psychophysics/>
  70.  
  71. The VideoToolbox sources can be linked to create a stand-alone C application, or
  72. a MATLAB external code resource (a "MEX" file), to be invoked by typing the
  73. function name from within MATLAB. In that case we call the THINK C project a
  74. "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
  75. every C file and must #include the VideoToolbox.h header at the beginning of every
  76. C file. You can simply "#define MATLAB 1"; VideoToolbox.h will redefine the 
  77. "MATLAB" symbol to correspond to the version of MATLAB defined by the MATLAB 
  78. header files, currently version 3, 4, or 5.
  79. Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
  80. window instead. E.g. you could type
  81.     #define MATLAB 1
  82. into the Prefix window.
  83.  
  84. You must have the file "mex.h" in order to compile this file when "MATLAB" is true.
  85. "mex.h" is distributed by MathWorks as part of MATLAB.
  86.  
  87. If you're using THINK C to create your MEX file, and you use QuickDraw, then
  88. you'll need PsychLibSources.h and CheckConfig.c from the Psychophysics Toolbox.
  89.  
  90. dgp & dhb.
  91. Copyright 1989-1997 © Denis G. Pelli
  92.  
  93. HISTORY: (omitting changes documented in C files)
  94. 2/20/93 dhb    Added various commonly used headers.  
  95.             Restructured so that only VideoToolbox.h has to be included,
  96.             whether one is creating stand-alone THINK C or code resources
  97.             to be called by MATLAB. Everything that cares is properly conditioned
  98.             by the symbol MATLAB.
  99. 7/9/93    dgp    Changed our convention for the MATLAB symbol, defining it as
  100.             1 or 0 instead of defining or leaving undefined. The advantage of
  101.             this approach is that "MATLAB" can now be used as an argument in an
  102.             ordinary if statement, which is much more readable than #if.
  103. 8/21/93    dhb    Added undefs in #if MATLAB so that memory allocation goes through THINK C 
  104.             library, not as callback. Callbacks would be OK except that the Mathworks 
  105.             forgot to give us one for realloc. This leads to mixing memory managers
  106.              on the same pointers -- bad bad bad.
  107. 9/2/93    dhb    commented out #include <TranslateLinefeeds.h> since it's
  108.             not presently compatible with MATLAB.
  109. 9/2/93    dgp    Moved the NL and NEWLINE macros from Assign.c into this file.
  110. 9/8/93    dgp    Mention VideoToolbox.c.
  111. 9/11/93    dhb,dgp    Define STDIO_INT and STDIO_DOUBLE.
  112. 9/12/93    dhb    Change STDIO_... to PRINTF_... and SCANF_...
  113.             Insert conditional for MATLAB 3.5 vs. 4.x
  114. 9/14/93    dhb    Conditional for MATLAB changed to make symbol match major version number.
  115.             Removed traces of old trying to force 4 byte ints for MATLAB.
  116. 9/14/93    dgp    Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
  117.             requires it. Fixed typo, changing "#elseif" to "#elif".
  118. 9/15/93    dgp    Edited the comments above, referring to VideoToolbox.c and the new 
  119.             VideoToolboxMATLAB.c. (Deleted VideoToolboxMATLAB.c on 9/16/96.)
  120. 9/16/93    dgp    Added contents of former Assign.h.
  121.             Defined MAC_C so that the VideoToolbox.h header may be used with
  122.             Standard C.
  123. 9/16/93    dhb Removed prototype for obsolete GetDateTimeString.
  124. 10/2/93    dgp    Added #include <Errors.h>.
  125. 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
  126. 12/16/93 dhb Somewhere things got munged.  Conditional for MATLAB version appeared
  127.            before inclusion of cmex, which won't work.  I fixed the order.
  128. 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below.  This
  129.            generates a link error from MATLAB.
  130. 12/29/93 dgp added #include <Packages.h>
  131. 6/12/94  dgp added definition of Apple's new BlockMoveData, for compatibility with
  132.             Apple's old pre-Universal header files.
  133. 6/12/94    dgp #include Strings.h if Universal header files are used.
  134. 7/28/94 dgp Added test for Metrowerks CodeWarrior C.
  135. 9/2/94    dgp #include MacMemory.h
  136. 9/5/94    dgp changed "int" to "short int" in definitions of PRINTF_INT and SCANF_INT for
  137.             MATLAB 4. This is based on common sense, not testing or detailed knowledge.
  138. 3/31/95    dgp    As a gesture of support for Symantec THINK C 8, now define THINK_C.
  139. 5/26/95 dgp Formerly header files whose precompilation depends on the mc68881 or 
  140.         mc68020 THINK C compiler options (i.e. math.h and mc68881.h) were omitted 
  141.         from VideoToolbox.h so that the resulting precompiled header file could be 
  142.         used in projects regardless of those options. However, for Metrowerks CodeWarrior
  143.         there's no advantage to omitting those headers, and a significant increase in
  144.         compile time, as fp.h is recompiled for each file. Since I've switch to
  145.         CodeWarrior, and expect most other users to switch as well, VideoToolbox.h now
  146.         includes math.h or fp.h.
  147. 5/27/95 dgp removed fp.c prototypes because Apple's fp.h now supports both 68k and ppc.
  148. 6/6/95 dgp discarded all references to TranslateLinefeeds.c and TranslateLinefeeds.h, since
  149.         I never got them to work properly, and I don't think they're needed with Metrowerks
  150.         CodeWarrior.
  151. 6/8/95 dgp Made sure that the MATLAB struct "Matrix" is always native aligned.
  152. 6/13/95 dgp define GENERATING68K, GENERATINGPOWERPC, and GENERATING68881 if not already
  153.         defined (as in Apple's latest universal headers). Define GENERATING68020.
  154. 6/14/95    dhb & dgp redefine the assert() macro, redirecting it to PrintfExit, which
  155.         in turn uses mex_error() to report the error. This is needed to get MEX files
  156.         to link properly.
  157. 6/16/95    dhb Fixed MATLAB's SCANF_INT etc. for __MWERKS__.
  158. 6/16/95 dgp moved the definitions of GENERATING68K to the top of this file, so that
  159.         the MATLAB conditionals can use them.
  160. 6/16/95    dhb    & dgp now #include <assert.h>, unless MATLAB is defined, in which case
  161.         we define a MATLAB-compatible version of the assert macro. Just in case,
  162.         leave NDEBUG defined to disable the standard assert macro which may be
  163.         brought in if the user's source files #include <assert.h>.
  164. 6/16/95    dhb    Fixed longstanding bug (in SCANF_INT??).
  165. 6/23/95    dhb    Include prototypes for AfterDark.c and IsFileSharingOn.c.
  166. 7/19/95 dgp Added changes suggested by Stefan Treue, streue@bcm.tmc.edu, for compatibility
  167.         with Symantec C. Eliminated use of //-style comments. Now include math.h
  168.         when compiling for Standard C, i.e. MAC_C is false.
  169. 8/10/95 dgp Include MacMemory.h ONLY for THINK C, not for Symantec C, since I don't
  170.         have any reason to think that Symantec C memory management is bad.
  171. 8/13/95 dgp Removed definition of THINK_C for SYMANTEC_C. It seems better to leave
  172.         the compiler's macros alone. Changed conditionals throughout the VideoToolbox
  173.         to deal with all the special cases: THINK_C, THINK_CPLUS, and SYMANTEC_C.
  174. 3/5/96    dhb Add conditional to prevent inclusion of <fp.h> and instead include <math.h>
  175.         when THINK_C is true.  This is needed to compile under THINK_C 8.  I suspect
  176.         that this used to work because the universal headers variable was < 2.
  177. 4/1/96    dgp removed "MAC_C" requirement for inclusion of fp.h. Tried to make VideoToolbox.h
  178.         more consistent with q_include.h, so both will work separately or together, in
  179.         either order, but I haven't checked whether I succeeded.
  180. 8/29/96    dhb & dgp updated for compatibility with MATLAB 5.
  181. 8/31/96 dhb  At dgp's suggestion, added macro mexFunctionEntry, which properly declares the
  182.         routine mexFunction according to which MATLAB version is being compiled.  Note that
  183.         prhs is declared as inprhs so that you can set prhs = inprhs and then modify it 
  184.         when compiling under version 5.  This assignment needs to be done in all source files.
  185. 9/5/95    dgp if !UNIVERSAL_HEADERS, typedef UInt32 and UnsignedWide, and prototype Microseconds.
  186. 11/96 dgp changed argument name from "explicit" to "isExplicit" since "explicit" is keyword in C++.
  187. 12/23/96 dgp now set MATLAB to MATLAB_VERSION, if defined (i.e. version 5 on).
  188. 1/22/97 dhb  Added prototype for IsAfterDarkEnabled.
  189. 1/25/97 dgp if MATLAB==4 #define mexWarnMsgTxt printf
  190. 2/17/97    dgp    if MATLAB==4 #define mexWarnMsgTxt printf("%s",s)
  191. 3/4/97    dhb    mexWarnMsgTxt conditionally uses TranslateEOL.
  192.         dhb Conditional macro for mexErrMsgTxt.
  193.         dhb    Prototype for TranslateEOL.
  194. 3/5/97    dgp    added Printf prototype. Polished the conditionals for THINK C MATLAB.
  195. 3/5/97    dgp    as suggested by david brainard, removed the obsolete NL and NEWLINE stuff.
  196. 3/13/97    dgp I upgraded to the latest THINK C, from the Symantec C++ 8 release 5  CD-ROM.
  197.             (THINK Project Manager 7.05; "translator" THINK C 8.0 or 8.1d1.)
  198.             Symantec has announced that they will no longer develop C or C++, so this is
  199.             probably the LAST version of THINK C. In this release, Symantec changed math.h:
  200.             removing "pi", and screwing up the definition of "long double" so that <math.h>
  201.             generates a compiler error when you use the "native floating point" and "8 byte double"
  202.             settings that are required to generate a MEX resource file for MATLAB.
  203.             With David Brainard's help, I've added conditionals to VideoToolbox.h to
  204.             work around both limitations. Unfortunately this new version of VideoToolbox.h
  205.             may not be compatible with the <math.h> included by Symantec with earlier versions
  206.             of THINK C. Sorry, please blame Symantec, not me. Over the past year,
  207.             David and I have worked with three different versions of THINK_C, all with
  208.             different versions of <math.h>, that nevertheless all identify themselves by
  209.             setting the preprocessor symbol THINK_C to 7. That makes it really hard for a
  210.             simple header file to provide version-specific fixs. (The conditionals are
  211.             specific to THINK_C so other compilers won't be affected.)
  212. 3/19/97    dgp    enhanced the VBLTaskAndA5 struct, removing the obsolete timer field, and adding
  213.             a new "seconds" field, as documented in VBLInstall.c
  214. 3/22/97    dgp    the definition of mex_qd, used solely by THINK C MEX projects, has been moved from
  215.             here to CheckConfig.c in the Psychophysics Toolbox, which may be obtained from:
  216.             <http://www.psych.ucsb.edu/~brainard/software/>
  217. 3/27/97    dgp    Updated the code defining GENERATING68881 to work with Apple's latest Universal Headers,
  218.             which now define that symbol, though they don't support THINK C. It now seems pointless
  219.             to retain support for Apple's pre-universal headers, so I've started stripping out
  220.             such code.
  221. 7/18/97    dgp    Made two fixs suggested by Tilman Vogel, tilman.vogel@uni-tuebingen.de, for compatibility
  222.             with the new CodeWarrior Pro 1. Changed an erroneous UNIVERSAL_HEADERS>2 to >=2 in 
  223.             deciding whether to look for Gestalt.h or GestaltEqu.h. Don't include fp.h if either 
  224.             __cmath__ or __MATH__ is defined.
  225. 7/31/97    dgp    Made VBLTaskAndA5.microTicks and VBLTaskAndA5.seconds volatile, since they're modified
  226.             at interrupt time. This change is in VideoToolbox.h.
  227. 7/31/97 dgp In a rush, I made Timer.interval, Timer.elapsed, Timer.elapsedIntervals volatile,
  228.             since (i'm not sure) they may be modified at interrupt time.
  229.             This may not be necessary, but can't hurt.             
  230. */
  231. #pragma once            /*  suppress multiple inclusions of this file */
  232. #ifndef _VIDEOTOOLBOX_    /*  suppress multiple inclusions of this file */
  233. #define _VIDEOTOOLBOX_
  234. /*
  235. Header files that are required for successful compilation of the rest of this
  236. file are marked "required".
  237. */
  238. #if !defined(MAC_C)
  239.     #if THINK_C    || THINK_CPLUS || SYMANTEC_C || defined(__SC__)            \
  240.         || applec            /* MPW C, presumably with Mac extensions */    \
  241.         || __MWERKS__        /* Metrowerks CodeWarrior C, " */
  242.         /* Set MAC_C to true only if the "pascal" keyword is allowed. */
  243.         #if THINK_C && !SYMANTEC_C
  244.             #if !__option(thinkc)
  245.                 #define MAC_C 0    /* Standard C */
  246.             #endif
  247.         #endif
  248.         #if SYMANTEC_C
  249.             #if __option(ansi_strict)
  250.                 #define MAC_C 0    /* Standard C */
  251.             #endif
  252.         #endif
  253.         #if __MWERKS__
  254.             #if __option(ANSI_strict) || __option(only_std_keywords)
  255.                 #define MAC_C 0    /* Standard C */
  256.             #endif
  257.         #endif
  258.         #if !defined(MAC_C)
  259.             #define MAC_C 1    /* allow Mac C extensions: "pascal", etc. */
  260.         #endif
  261.     #else
  262.         #define MAC_C 0        /* Standard C */
  263.     #endif
  264. #endif
  265. #ifndef SHORT_DOUBLE_OK
  266.     #if SYMANTEC_C
  267.         #define SHORT_DOUBLE_OK 0        /* "short double" not supported by Symantec C */
  268.     #else
  269.         #define SHORT_DOUBLE_OK MAC_C    /* "short double" not allowed by Standard C */
  270.     #endif
  271. #endif
  272. #include <stdio.h>            /*  required */
  273. #include <stdlib.h>
  274. #if MAC_C
  275.     #include <Quickdraw.h>    /*  required */
  276. #endif
  277. /*
  278. The inclusion, above, of Quickdraw.h will result in the inclusion of MixedMode.h
  279. only if the Universal Headers are used, since the Universal Headers and the Mixed
  280. Mode Manager are both new, providing universal support for 68k and ppc Macs.
  281. */
  282. #if defined(__MIXEDMODE__)
  283.     #if defined(GENERATINGPOWERPC) || defined(GENERATING68K)
  284.         #define UNIVERSAL_HEADERS 2    /* version 2 */
  285.     #else
  286.         #define UNIVERSAL_HEADERS 1    /* version 1 */
  287.     #endif
  288. #else
  289.     #define UNIVERSAL_HEADERS 0
  290.     #error "Need Apple's Universal Headers"
  291. #endif
  292.  
  293. /* Apple's ConditionalMacros.h header defines GENERATING68881, but doesn't support THINK C,
  294. so we handle that case here. */
  295. #if THINK_C || THINK_CPLUS
  296.     #undef GENERATING68881
  297.     #if THINK_C && THINK_C==1        /* THINK C 4 */
  298.         #define GENERATING68881 _MC68881_
  299.     #endif
  300.     #if THINK_CPLUS || (THINK_C && THINK_C>1)    /* THINK C 5,6,7,8, C++, SYMANTEC C,C++ */
  301.         #if __option(mc68881)
  302.             #define GENERATING68881 1
  303.         #endif
  304.     #endif
  305. #endif
  306. #ifndef GENERATING68881
  307.     #define GENERATING68881 0
  308. #endif
  309.  
  310. /* Apple's headers don't define GENERATING68020, but Identify.c and Require.c need it. */
  311. #if GENERATING68K && !defined(GENERATING68020)
  312.     #if defined(applec) || defined(__SC__)
  313.         #ifdef mc68020
  314.             #define GENERATING68020 1
  315.         #endif
  316.     #else
  317.         #if THINK_C && THINK_C==1            /* THINK C 4 */
  318.             #define GENERATING68020 _MC68020_
  319.         #endif
  320.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* Symantec C, THINK C 5,6,7,8 */
  321.             #if __option(mc68020)
  322.                 #define GENERATING68020 1
  323.             #endif
  324.         #endif
  325.         #if __MWERKS__
  326.             #if __MC68020__
  327.                 #define GENERATING68020 1
  328.             #endif
  329.         #endif
  330.     #endif
  331. #endif
  332. #if !defined(GENERATING68020)
  333.     #define GENERATING68020 0
  334. #endif
  335.  
  336. #if !defined(MATLAB)
  337.     #define MATLAB 0
  338. #endif
  339. #if MATLAB
  340.     /*
  341.     This must come after stdlib.h, stdio.h, and QuickDraw.h, and before everything
  342.     else. If MATLAB is true then we include the header file cmex.h.  Otherwise we
  343.     define the data types that are normally provided by that header, so that code
  344.     that uses these types may be compiled for use in applications.  It must come
  345.     before we test for version.  The version 3 cmex.h does not define the
  346.     symbol mex_h; subsequent versions do.  This is what we use to figure out which
  347.     version we are compiling for.  Sound complicated?  Sigh! dhb
  348.     */
  349.     
  350.     #include "mex.h"
  351.     /* Test for MATLAB version 5,4, or 3, and set symbol appropriately. */
  352.     #undef MATLAB
  353.     #ifdef mex_h
  354.         #ifdef MATLAB_VERSION
  355.             #define MATLAB MATLAB_VERSION    /* for version 5 and higher */
  356.         #else
  357.             #define MATLAB 4
  358.         #endif
  359.     #else
  360.         #define MATLAB 3
  361.     #endif
  362.     #if !MAC_C
  363.         #error "MATLAB requires the Macintosh extensions to C."
  364.     #endif
  365.  
  366.     /*
  367.     Undefine the macros that override memory allocation.  MATLAB's implementation
  368.     doesn't work if you use realloc.
  369.     */
  370.     #undef malloc
  371.     #undef calloc
  372.     #undef free
  373.     
  374.     /* Define data types for printf, scanf. */
  375.     #if (MATLAB == 4 || MATLAB == 5)
  376.     /* Version 4 or 5 */
  377.         #if GENERATING68K
  378.             typedef short int PRINTF_INT;        /* type of arguments to printf et al. */
  379.             typedef long double PRINTF_DOUBLE;
  380.             typedef    int SCANF_INT;                /* type of arguments to scanf et al. */
  381.             typedef double SCANF_DOUBLE;
  382.         #endif
  383.         #if GENERATINGPOWERPC
  384.             typedef int PRINTF_INT;                /* type of arguments to printf et al. */
  385.             typedef double PRINTF_DOUBLE;
  386.             typedef int SCANF_INT;                /* type of arguments to scanf et al. */
  387.             typedef double SCANF_DOUBLE;
  388.         #endif
  389.         #if THINK_C || THINK_CPLUS
  390.             // redirect all printing to go through TranslateEOL() in PrintfExit.c
  391.             #undef printf
  392.             #undef mexPrintf
  393.             #undef mexErrorMsgTxt
  394.             #define printf Printf
  395.             #define mexPrintf Printf
  396.             #define mexErrMsgTxt(s) mexErrMsgTxt(TranslateEOL(s))
  397.         #endif
  398.         #if MATLAB == 4
  399.             #define mxArray Matrix
  400.             #define mxREAL REAL
  401.             #define mxIsChar mxIsString
  402.             #define mxDestroyArray mxFreeMatrix
  403.             #define mxCreateDoubleMatrix mxCreateFull
  404.             typedef mxArray CONSTmxArray;
  405.             #undef mexWarnMsgTxt
  406.             #if THINK_C || THINK_CPLUS
  407.                 #define mexWarnMsgTxt(s) Printf("%s",s)
  408.             #else
  409.                 #define mexWarnMsgTxt(s) printf("%s",s)
  410.             #endif
  411.         #else
  412.             typedef const mxArray CONSTmxArray;
  413.             #if THINK_C || THINK_CPLUS
  414.                 #undef mexWarnMsgTxt
  415.                 #define mexWarnMsgTxt(s) mexWarnMsgTxt(TranslateEOL(s))
  416.             #endif
  417.         #endif
  418.     #endif
  419. #else
  420.     typedef long int INT;
  421.     #if SHORT_DOUBLE_OK
  422.         typedef short double DOUBLE;/* not allowed by Standard C */
  423.     #else
  424.         typedef double DOUBLE;
  425.     #endif
  426.     typedef int PRINTF_INT;            /* type of arguments to printf et al. */
  427.     typedef double PRINTF_DOUBLE;
  428.     typedef int SCANF_INT;            /* type of arguments to scanf et al. */
  429.     typedef double SCANF_DOUBLE;
  430.     #if SHORT_DOUBLE_OK
  431.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  432.             #pragma options align=native
  433.         #endif
  434.         typedef struct {
  435.             char *name;
  436.             INT type;
  437.             INT m;
  438.             INT n;
  439.             DOUBLE *pr;
  440.             DOUBLE *pi;
  441.         } Matrix;
  442.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  443.             #pragma options align=reset
  444.         #endif
  445.     #endif
  446. #endif
  447.  
  448. /*  Standard C headers */
  449. #if MATLAB
  450.     /* The <assert.h> macro requires modification to work in a MATLAB shared library. */
  451.     #define NDEBUG        /* disable the standard assert.h macro */
  452.     #undef assert
  453.     #define assert(x)    if(!(x)){\
  454.         PrintfExit("Assertion (" #x ") failed at %s:%d",__FILE__,__LINE__);\
  455.     }
  456. #else
  457.     #include <assert.h>
  458. #endif
  459. #include <ctype.h>
  460. #include <float.h>
  461. #include <limits.h>
  462. #include <stdlib.h>
  463. #include <string.h>
  464. #include <time.h>
  465. #if !defined(__MATH__) && !defined(__cmath__) && (UNIVERSAL_HEADERS>=2) && !(THINK_C || THINK_CPLUS)
  466.     #include <fp.h>
  467. #else
  468.     #if GENERATINGPOWERPC || GENERATING68881
  469.         /* as advised by math.h, we don't enable these if using 8-byte doubles on 68k */
  470.         #undef _NOERRORCHECK_
  471.         #undef _INLINE_FPU_CALLS_
  472.         #define _NOERRORCHECK_ 1        /* encourage use of 8881 intrinsic functions */
  473.         #define _INLINE_FPU_CALLS_ 1    /* encourage use of 8881 intrinsic functions */
  474.     #endif
  475.     #if THINK_C==7                        // Fix THINK C <math.h> in Symantec's C++ 8 release 5.
  476.         #define SAVE_THINK_C 7
  477.         #undef THINK_C
  478.         #define THINK_C 0
  479.     #endif
  480.     #include <math.h>
  481.     #if SAVE_THINK_C==7                    // Restore "THINK_C".
  482.         #undef THINK_C
  483.         #define THINK_C 7
  484.         #undef SAVE_THINK_C
  485.     #endif
  486.     #if !defined(__FP__)    /* make sure that math.h hasn't included fp.h */
  487.         #undef round
  488.         #define round(x) floor(0.5+(x))    /* used by many VideoToolbox routines */
  489.     #endif
  490. #endif
  491.  
  492. /*  Macintosh headers */
  493. #if MAC_C
  494.     #if THINK_C || THINK_CPLUS || SYMANTEC_C
  495.         #include <console.h>
  496.     #endif
  497.     #include <Devices.h>
  498.     #include <Errors.h>
  499.     #include <Events.h>
  500.     #include <FixMath.h>
  501.     #include <Fonts.h>
  502.     #if UNIVERSAL_HEADERS>=2
  503.         #include <Gestalt.h>    /* Apple abbreviated the filename */
  504.     #else
  505.         #include <GestaltEqu.h>
  506.     #endif
  507.     #include <Memory.h>
  508.     #include <Menus.h>
  509.     #include <OSEvents.h>
  510.     #include <OSUtils.h>    /*  required */
  511.     #include <Packages.h>
  512.     #include <Palettes.h>
  513.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  514.         #include <profile.h>/* only needed if you want timing info */
  515.     #endif
  516.     #include <QDOffscreen.h>
  517.     #include <Resources.h>
  518.     #include <Retrace.h>    /*  required */
  519.     #if __MWERKS__
  520.         #include <SIOUX.h>
  521.     #endif
  522.     #include <Slots.h>
  523.     #include <Sound.h>
  524.     #if THINK_C && !UNIVERSAL_HEADERS
  525.         #include <pascal.h>    /* CtoPStr() and PtoCStr() */
  526.         #ifndef c2pstr
  527.             #define c2pstr(s) CtoPstr(s)
  528.             #define p2cstr(s) PtoCstr(s)
  529.         #endif
  530.     #else
  531.         #include <Strings.h>/* c2pstr() and p2cstr() */
  532.         #define CtoPstr c2pstr
  533.         #define PtoCstr p2cstr
  534.     #endif
  535.     #include <Timer.h>        /*  required */
  536.     #include <ToolUtils.h>
  537.     #include <Traps.h>
  538.     #include <Video.h>
  539.     #include <Windows.h>    /*  required */
  540.     /*
  541.     Old Memory.h header files, before Apple's Universal Headers, don't define the new
  542.     BlockMoveData(), so we do it here, to retain compability with the old header files.
  543.     */
  544.     #if !UNIVERSAL_HEADERS
  545.         #pragma parameter BlockMoveData(__A0,__A1,__D0)
  546.         extern pascal void BlockMoveData(const void *srcPtr,void *destPtr,Size byteCount)=0xA22E;
  547.     #endif
  548. #endif
  549.  
  550. /*
  551. This redefines the standard C functions, malloc, etc. to instead call Apple's
  552. corresponding routines, e.g. NewPtr. The THINK C memory management routines are 
  553. poor because they are bad about freeing space, tending to fragment the free space. 
  554. */
  555. #if THINK_C && !defined(SYMANTEC_C)
  556.     #include "MacMemory.h"
  557. #endif
  558.  
  559. /*
  560. TRUE and FALSE
  561. */
  562. #ifndef TRUE
  563.     #define FALSE    0
  564.     #define TRUE    1
  565. #endif
  566.  
  567. /*
  568. NAN & INF
  569. If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
  570. IsFinite() definitions & prototypes below. 
  571. Apple's fp.h header defines isnan() and isfinite().
  572. Apple's header files math.h and fp.h both define HUGE_VAL and pi.
  573. fp.h also defines INFINITY, NAN, isfinite(), and isnan().
  574. */
  575. #if !defined(INF)
  576.     #define INF HUGE_VAL    /* HUGE_VAL is defined in math.h and fp.h */
  577. #endif
  578. #if !defined(NAN)
  579. /*    #define NAN    (0.0/0.0)    */    /* evaluated at runtime */
  580.     #define NAN    Nan            /* global defined in Nan.c */
  581. #endif
  582.  
  583. /*
  584. NUMERICAL CONSTANTS
  585. It's sad to say, but THINK C 5.02 loses two bits of precision converting between
  586. doubles and ascii text, in either direction. Thus, if you're using THINK C,
  587. you will obtain more accurate
  588. results by computing the numerical constants below at runtime rather than using
  589. these predefined constants. The ANSI Numerical C Extensions group is moving to
  590. require C compilers to preserve precision, so there is hope for the future. Of
  591. course most applications would never notice a loss of two bits precision out of
  592. the total double precision given by the 64 bits in the mantissa.
  593. */
  594. #if !defined(PI)
  595.     #if UNIVERSAL_HEADERS>=2 && !(THINK_C || THINK_CPLUS)
  596.         #define PI        pi                        /* pi is defined in math.h and fp.h */
  597.     #else
  598.         #define PI        3.1415926535897932385    /* computed in Mathematica */
  599.     #endif
  600. #endif
  601. #if !defined(LOGPI)
  602.     #define LOGPI    1.14472988584940017414    /* computed in Mathematica */
  603. #endif
  604. #if !defined(LOG2)
  605.     #define LOG2    0.69314718055994530942    /* computed in Mathematica */
  606. #endif
  607. #if !defined(LOG10)
  608.     #define LOG10    2.30258509299404568402    /* computed in Mathematica */
  609. #endif
  610.  
  611. #if MAC_C
  612.     /*
  613.     CLUTSIZE
  614.     Inline code that returns the same answer as GDClutSize(device).
  615.     */
  616.     #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
  617.     
  618.     /*  Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
  619.     /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
  620. #endif
  621.  
  622. /*
  623. FIXED POINT ARITHMETIC
  624. Apple defines a handy data type called Fixed that is stored in a long, but is
  625. assumed to have a decimal point in the middle. Many operations, e.g. adding two
  626. Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
  627. directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
  628. FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
  629. compilers define double in various ways, depending on whether a floating point
  630. unit is to be used. The Apple-provided routines for doing type conversion to and
  631. from Fixed are only appropriate if you are NOT using the floating point unit.
  632. The ones defined below are faster and work with or without the FPU.
  633. */
  634. #define LongToFix(x) ((long)(x)<<16)
  635. #define FixToLong(x) ((x)>>16)
  636. #define DoubleToFix(x) ((long)((x)*65536.+0.5))
  637. #define FixToDouble(x) ((double)(x)*(1./65536.))
  638.  
  639. #if MAC_C
  640.     /*
  641.     StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
  642.     Apple's StackSpace(), declared in Memory.h, that returns the number of bytes 
  643.     allocated for the stack.
  644.     */
  645.     #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
  646. #endif
  647.  
  648. #if MAC_C
  649.     /* AfterDark.c */
  650.  
  651.     OSErr AfterDarkEnable(void);
  652.     OSErr AfterDarkDisable(void);
  653.     Boolean IsAfterDarkEnabled(void);
  654.  
  655. #endif
  656.  
  657. /* Assign.c */
  658.  
  659. #define ASSIGN_DIMS 3        /* Feel free to increase or decrease ASSIGN_DIMS. */
  660. typedef struct {
  661.     short type;
  662.     unsigned sizedOnce:1;    /* dim[] is meaningful */
  663.     unsigned sized:1;        /* dim[] is final */
  664.     unsigned malloced:1;    /* allocated by malloc */
  665.     char *name;
  666.     void *ptr;                /* for array, address of element zero */
  667.     long dim[ASSIGN_DIMS];    /* zero indicates a scalar */
  668.     long firstElement;        /* for 1-d array, index of first array element. Usually 0 */
  669.     const char *comment;    /* text string, or NULL */
  670. } Description;
  671. enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
  672.     ,assignNoComment=8,assignNoPrintfExit=0x10
  673.     ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
  674. };
  675. enum {assignMemoryError=-1,assignTypeError=-2
  676.     ,assignVariableError=-3,assignUnknownVariableError=-4
  677.     ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
  678.     ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
  679.     ,assignSemicolonError=-10,assignFileError=-11
  680.     ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
  681.     ,assignInconsistentDimensionsError=-14
  682.     ,assignCouldntFindDescription=-15
  683. };
  684. enum{charType=1,unsignedCharType,shortType,unsignedShortType
  685.     ,longType,unsignedLongType
  686.     ,floatType
  687.     #if SHORT_DOUBLE_OK
  688.         ,shortDoubleType
  689.     #endif
  690.     ,doubleType
  691.     ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
  692.     ,longPtrType,unsignedLongPtrType
  693.     ,floatPtrType
  694.     #if SHORT_DOUBLE_OK
  695.         ,shortDoublePtrType
  696.     #endif
  697.     ,doublePtrType
  698.     ,stringType,unknownType
  699. };
  700. FILE *OpenCalFileRead(char *filename);
  701. FILE *OpenCalFileReadAndCheck(char *filename);
  702. FILE *OpenCalFileWrite(char *filename);
  703. void AppendDescriptions(Description **d,Description *s);
  704. void CopyDescriptions(Description *d,Description *s);
  705. Description *AllocateDescriptions(long n);
  706. void FreeDescriptions(Description *d);
  707. long NumberOfDescriptions(Description *d);
  708. Description NullDescription(void);
  709. int IsNullDescription(Description d);
  710. #define IsNullDescription(d) ((d).type==0)
  711. int AssignmentLineWasBlank(void);
  712. int UnequalDescribedVars(Description d1[],Description d2[],short flags);
  713. int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
  714. int CopyDescribedVars(Description d1[],Description d2[],short flags);
  715. int CopyDescribedVarPair(Description *d1,Description *d2,short flags);
  716. long InitializeADescribedVar(Description *d,short flags);
  717. long InitializeDescribedVars(Description d[],short flags);
  718. long FindDescribedDim(Description d[],void *ptr,int i,short flags);
  719. long FindDescription(Description d[],void *ptr,short flags);
  720. void FreeADescribedVar(Description *d,short flags);
  721. void FreeDescribedPtrVars(Description d[],short flags);
  722. void FreeDescribedVars(Description d[],short flags);
  723. void KeepDescribedVars(Description d[],short flags);
  724. void KeepADescribedVar(Description *d,short flags);
  725. long PrintAnAssignment(FILE *stream,Description *d,short flags);
  726. long PrintAssignments(FILE *stream,Description d[],short flags);
  727. long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
  728. long ReadAssignmentLine(FILE *stream,Description d[],short flags);
  729. long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
  730. long ReadAssignmentStream(FILE *stream,Description d[],short flags);
  731. long ReadAssignmentFile(const char *filename,Description d[],short flags);
  732. Description Describe(short type,void *ptr,char *name,const char *comment);
  733. Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
  734. Description DescribeFirstLast(short type,void *ptr,char *name
  735.     ,const char *comment,long firstElement,long lastElement);
  736.  
  737. #if MAC_C
  738.     /* AtExitToShell.c */
  739.     
  740.     int AtExitToShell(void(*userFunctionPtr)(void));
  741. #endif
  742.  
  743. /* Binomial.c */
  744.  
  745. long    BinomialSample(double p,long n);
  746. int        BinomialSampleQuickly(int n);
  747. double    BinomialLowerBound(double P,long k,long n);
  748. double    BinomialUpperBound(double P,long k,long n);
  749. double    BinomialPdf(double p,long k,long n);
  750. double    Binomial(double p,long k,long n);
  751. double    IncompleteBeta(double x,double a,double b);
  752. double    InverseBinomial(double P,long k,long n);
  753. double    InverseIncompleteBeta(double p,double a,double b);
  754.  
  755. /* BreakLines.c */
  756.  
  757. char *BreakLines(char *string,long lineLength);
  758. void PrintWrappedText(FILE *stream,const char *s);
  759. void PrintWrappedTextToFile(const char *filename,const char *s);
  760. void PrintWrappedComment(FILE *stream,const char *s);
  761. void PrintWrappedCommentToFile(const char *filename,const char *s);
  762.  
  763. #if MAC_C
  764.     /* CardSlot.c */
  765.     
  766.     OSErr    CardSlot(char *cardName);
  767.     
  768.     /* CenterRectInRect.c */
  769.     
  770.     void CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
  771.     void PinRectInRect(Rect *a,Rect *b);
  772.     void OffsetRectTile(Rect *r,int nx,int ny);
  773.     Boolean IsRectInRect(Rect *r,Rect *R);
  774.     void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  775.     void ExpandRect(Rect *r,double hMag,double vMag);
  776.     void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  777.     void LocalToGlobalRect(Rect *r);
  778.     void GlobalToLocalRect(Rect *r);
  779.  
  780. #endif
  781.  
  782. /* ChiSquare.c */
  783.  
  784. double    PChiSquare (double chiSquare,int n);
  785.  
  786. /* Choose.c */
  787.  
  788. #if !MAC_C
  789.     #define Boolean unsigned char
  790. #endif
  791. int Choose(int defaultChoice,const char *query,char *choices[],int n);
  792. char *ChoiceStr(char *choices[],int n);
  793. int MultipleChoice(short defaultChoice,short n,char *choices[]);
  794. Boolean YesOrNo(Boolean defaultAnswer);
  795. extern char *noYes[];
  796. #if !MAC_C
  797.     #undef Boolean
  798. #endif
  799.  
  800. #if MAC_C
  801.     /* ChooseScreen.c */
  802.     
  803.     int ChooseScreen(int screen,const char *question);
  804.  
  805.     /* CommandPeriod.c */
  806.  
  807.     Boolean CommandPeriod(void);
  808.     short    GetNextEventOrQuit(int mask,EventRecord *eventPtr);
  809.     Boolean WaitNextEventOrQuit(int mask,EventRecord *eventPtr,unsigned long sleep,RgnHandle mouseRgn);
  810.  
  811.     /* ConvolveX.c */
  812.     
  813.     void ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  814.                 Rect *srcRectPtr,Rect *dstRectPtr);
  815.  
  816.     /* ConvolveY.c */
  817.     
  818.     void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  819.                 Rect *srcRectPtr,Rect *dstRectPtr);
  820.     
  821.     /* CopyBitsQuickly.c */
  822.     
  823.     enum{addOverQuickly=40,addOverParallel=40,mulOver};
  824.     int    CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits
  825.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  826.     
  827.     /* CopyQuickDrawGlobals.c */
  828.     
  829.     void CopyQuickDrawGlobals(void);
  830.     #define CopyQuickdrawGlobals CopyQuickDrawGlobals    /*  old spelling */
  831.     
  832.     /* CopyWindows.c */
  833.     
  834.     enum{copyLiterally=0x10000,copyColorize=0x20000};
  835.     enum{srcCopyLiterally=srcCopy+copyLiterally,addOverLiterally=addOver+copyLiterally
  836.         ,addOverParallelLiterally=addOverParallel+copyLiterally
  837.         ,mulOverLiterally=mulOver+copyLiterally};
  838.     int CopyWindows(CWindowPtr srcWindow,CWindowPtr dstWindow
  839.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  840.  
  841.     /* CreateTrialSnds.c */
  842.     
  843.     void CreateTrialSnds(void);
  844. #endif
  845.  
  846. /* DatedString.c */
  847.  
  848. char    *DatedString(unsigned long seconds);
  849.  
  850. #if MAC_C
  851.     /* DrawPrintf.c */
  852.     
  853.     void DrawPrintf(char *s, ...);
  854. #endif
  855.  
  856. /* Exponential.c */
  857.  
  858. double ExponentialPdf(double x);
  859.  
  860. /* ffprintf.c */
  861.  
  862. int ffprintf(FILE *stream[2],char *format,...);
  863.  
  864. #if MAC_C
  865.     /* FlushCacheRange.c */
  866.     
  867.     void FlushCacheRange (void *address, unsigned long count);
  868.     
  869.     /* GDOpenWindow.c */
  870.     
  871.     void AddExplicitPalette(WindowPtr window);
  872.     void RemovePalette(WindowPtr window);
  873.     WindowPtr GDOpenWindow1(GDHandle device);
  874.     void GDDisposeWindow1(WindowPtr window);
  875.     CWindowPtr GDOpenWindow(GDHandle device);
  876.     void GDDisposeWindow(CWindowPtr myWindow);
  877.     void GDGrayColorTable(GDHandle device);
  878.     void GDStandardColorTable(GDHandle device,Boolean isColor);
  879.     void SwapWindowExplicitMode(CWindowPtr window,Boolean *isExplicit);
  880.     BitMap *GetBitMapPtr(CWindowPtr window);
  881.     Boolean IsGWorldPtr(CWindowPtr window);
  882.     Boolean IsGrafPtr(CWindowPtr window);
  883.     
  884.     /* GDPrintf.c */
  885.     
  886.     void GDPrintf(char *s, ...);
  887.     
  888.     /* GDTime.c */
  889.     
  890.     double GDFrameRate(GDHandle device);
  891.     double GDMovieRate(GDHandle device,int quickly);
  892.     double GDMovieSize(GDHandle device,int quickly);
  893.     double GDVBLRate(GDHandle device);
  894.     double TickRate(void);
  895.     typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
  896.         ,ColorSpec *aTable);
  897.     OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
  898.         ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
  899.     
  900.     /* GDVideo.c */
  901.     
  902.     #define MAX_SCREENS 8
  903.     OSErr DriverGestalt(int refNum,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  904.     OSErr GDGestalt(GDHandle device,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  905.     Boolean GDGestaltIsOn(GDHandle device);
  906.     char  *GDCardName(GDHandle device);
  907.     extern short gdClutSizeTable[33];
  908.     short GDClutSize(GDHandle device);
  909.     long GDColors(GDHandle device);
  910.     OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
  911.     short GDDacSize(GDHandle device);
  912.     OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  913.     OSErr GDDisposeGamma(GDHandle device);
  914.     OSErr GDGetDisplayMode(GDHandle device,unsigned long *displayModeIDPtr
  915.         ,unsigned short *modePtr,unsigned short *pagePtr,Ptr *baseAddrPtr);
  916.     OSErr GDGetNextResolution(GDHandle device,unsigned long previousDisplayModeID
  917.         ,unsigned long *displayModeIDPtr,unsigned long *horizontalPixelsPtr
  918.         ,unsigned long *verticalLinesPtr,Fixed *refreshRatePtr
  919.         ,unsigned short *maxDepthModePtr);
  920.     OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
  921.     OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
  922.     OSErr GDGetDelay(GDHandle device,Boolean *dontWaitForVBLPtr,double *nanosecondsPtr);
  923.     OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  924.     OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
  925.     OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
  926.     OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
  927.     OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  928.     OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
  929.     OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
  930.     OSErr GDGrayPage(GDHandle device,short page);
  931.     Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
  932.     short GDModePixelSize(GDHandle device,short mode);
  933.     unsigned char *GDName(GDHandle device);
  934.     char *GDNameStr(GDHandle device);
  935.     ColorSpec *GDNewLinearColorTable(GDHandle device);
  936.     short GDPixelSize(GDHandle device);
  937.     OSErr GDPrintGammaTable(FILE *o,GDHandle device);
  938.     OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  939.     OSErr GDRestoreDeviceClut(GDHandle device);
  940.     OSErr GDRestoreGamma(GDHandle device);
  941.     OSErr GDSaveGamma(GDHandle device);
  942.     OSErr GDSetDefaultMode(GDHandle device,short mode);
  943.     OSErr GDSetDelay(GDHandle device,Boolean dontWaitForVBL,double nanoseconds);
  944.     OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  945.     OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
  946.     OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
  947.         ,ColorSpec *table);
  948.     OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
  949.     OSErr GDSetGray(GDHandle device,Boolean flag);
  950.     OSErr GDSetInterrupt(GDHandle device,Boolean flag);
  951.     OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
  952.     OSErr GDSetPageDrawn(GDHandle device,short page);
  953.     OSErr GDSetPageShown(GDHandle device,short page);
  954.     OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
  955.     OSErr GDSwitchMode(GDHandle device,short mode,long displayModeID,short page,Ptr *baseAddrPtr);
  956.     short GDType(GDHandle device);
  957.     OSErr GDUncorrectedGamma(GDHandle device);
  958.     int GDVersion(GDHandle device);
  959.     int PatchMacIIciVideoDriver(void);
  960.     Boolean IsPCIMac(void);
  961.     void GDRestoreBlackAndWhite(GDHandle device);
  962.     
  963.     /* GetClicks.c */
  964.     
  965.     short    GetClicks(void);
  966.  
  967.     /* GetScreenDevice.c */
  968.     
  969.     GDHandle    GetScreenDevice(int n);
  970.     int            GetScreenIndex(GDHandle device);
  971.     GDHandle    SlotToScreenDevice(int n);
  972.     GDHandle    GetDeviceByRefNum(int n);
  973.     short int    GetDeviceSlot(GDHandle device);            /* gives nonsense on PCI bus */
  974.     char        *GetDeviceSlotName(GDHandle device);    /* works on NuBus, PCI bus, and no bus */
  975.     GDHandle    GetWindowDevice(WindowPtr theWindow);
  976.     GDHandle    GetRectDevice(Rect *r);
  977.  
  978. #endif
  979.  
  980. /* GetTimeDateString.c */
  981.  
  982. char *GetTimeDateString(time_t t);
  983.  
  984. #if MAC_C
  985.     /* GetVersionString.c */
  986.  
  987.     char *GetVersionString(void);
  988.  
  989.     /* GetVoltage.c */
  990.     
  991.     double    VoltsDuringFrame(double frames);
  992.     double    GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
  993.                 ,double *sdPtr);
  994.     short    GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
  995.                 ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
  996.     short    InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
  997.                 ,double *voltDeltaPtr,double *voltZeroPtr);
  998.     short    RetrieveVoltages(long *nPtr,unsigned short readings[]);
  999.     int        ForeRunnerSlot(void);
  1000.     enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
  1001. #endif
  1002.  
  1003. /* HexToBinary.c */
  1004.  
  1005. int HexToBinary(char *string,void *ptr);
  1006. char *BinaryToHex(size_t n,void *ptr,char *string);
  1007.  
  1008. #if MAC_C
  1009.     /* HideMenuBar.c */
  1010.     
  1011.     void    HideMenuBar(void);
  1012.     void    ShowMenuBar(void);
  1013.     void SquareCorners(GDHandle device);
  1014.     void RestoreCorners(GDHandle device);
  1015.     void UnclipScreen(GDHandle device);
  1016.     void RestoreScreenClipping(GDHandle device);
  1017.     
  1018.     /* Identify.c */
  1019.     
  1020.     char *IdentifyApplication(void);
  1021.     char *IdentifyCompiler(void);
  1022.     char *IdentifyGreenwichMeanTime(void);
  1023.     char *IdentifyMachine(void);
  1024.     char *IdentifyModel(void);
  1025.     char *IdentifyOwner(void);
  1026.     char *IdentifyVideo(GDHandle device);
  1027.     char *IdentifyVM(void);
  1028.     
  1029.     /* ImageStatistics */
  1030.  
  1031.     double ImageEnergy(GWorldPtr aWorld,Rect *aRect,double background);
  1032.     void ImageStatistics(GWorldPtr world,Rect *rect
  1033.         ,long *minPtr,long *maxPtr,double *meanPtr,double *meanSquarePtr);
  1034.  
  1035.     /* InstallGestaltValue.c */
  1036.  
  1037.     OSErr InstallGestaltValue(OSType selector,long response);
  1038.  
  1039.     /* IsCmdPeriod.c */
  1040.     
  1041.     Boolean IsCmdPeriod(EventRecord *event);
  1042.  
  1043.     /* IsFileSharingOn.c */
  1044.  
  1045.     Boolean IsFileSharingOn(void);
  1046.     OSErr KillFileSharing(void);
  1047.  
  1048. #endif
  1049.  
  1050. /* IsNan.c */
  1051.  
  1052. int IsNan(double x);
  1053. int IsInf(double x);
  1054. #ifndef IsFinite    /* neither NAN nor ±INF */
  1055.     #define IsFinite(x) \
  1056.     (sizeof(x)>8?    \
  1057.     ((*(short *)&(x) & 0x7FFF)!=0x7FFF)        /* 10 or 12 byte double */\
  1058.     :((*(short *)&(x) & 0x7FF0)!=0x7FF0))    /* 8 byte double */
  1059. #endif
  1060.  
  1061. #if MAC_C
  1062.     /* IsWindow.c */
  1063.     Boolean IsWindow(WindowPtr window);
  1064.  
  1065.     /* kbhit.c */
  1066.     
  1067.     int    kbhit(void);
  1068.     int    getcharUnbuffered(void);
  1069.  
  1070.     /* KillEveryoneButMe.c */
  1071.     
  1072.     OSErr KillEveryoneButMe(void);
  1073. #endif
  1074.  
  1075. /* Log2L.c */
  1076.  
  1077. long Log2L(unsigned long j);
  1078.  
  1079. #if MAC_C
  1080.     
  1081.     /* MaximizeConsoleHeight.c */
  1082.     
  1083.     void MaximizeConsoleHeight(void);
  1084. #endif
  1085.  
  1086. /* Mean.c */
  1087.  
  1088. double Mean(double x[],long n,double *sdPtr);
  1089. double MeanF(float x[],long n,double *sdPtr);
  1090. double MeanB(char x[],long n,double *sdPtr);
  1091. double MeanUB(unsigned char x[],long n,double *sdPtr);
  1092. double MeanW(short x[],long n,double *sdPtr);
  1093. double MeanUW(unsigned short x[],long n,double *sdPtr);
  1094. double MeanL(long x[],long n,double *sdPtr);
  1095. double MeanUL(unsigned long x[],long n,double *sdPtr);
  1096.  
  1097. /* Nan.c */
  1098. extern const short __NAN[];
  1099. #define Nan (*(double *)__NAN)
  1100.  
  1101. #if MAC_C
  1102.     /* NoiseFill.c */
  1103.     
  1104.     int NoiseFill(CWindowPtr window,Rect *r,double dx,double dy,Boolean randomPhase);
  1105.     int NoiseFillBits(PixMap *bits,Rect *r,double dx,double dy,Boolean randomPhase);
  1106.     int MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *bits);    /* Obsolete */
  1107.     
  1108.     /* NoisePdfFill.c */
  1109.     
  1110.     OSErr NoisePdfFill(GWorldPtr world,Rect *rectPtr
  1111.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1112.     OSErr NoisePdfAdd(GWorldPtr world,Rect *rectPtr
  1113.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1114.     enum{kBinaryPdf=0,kBinomialPdf,kGaussianPdf,kUniformPdf};
  1115. #endif
  1116.  
  1117. /* Normal.c */
  1118.  
  1119. double NormalPdf(double x);
  1120. double Normal(double x);
  1121. double InverseNormal(double p);
  1122. double NormalSample(void);
  1123. double Normal2DPdf(double r);
  1124. double Normal2D(double r);
  1125. double InverseNormal2D(double p);
  1126. double Normal2DSample(void);
  1127. double InverseNormal2DPdf(double p);
  1128. void BoundedNormalIntegers(short *distribution,long n,double mean,double sd
  1129.     ,short min,short max);
  1130.  
  1131. /* nrand.c */
  1132.  
  1133. unsigned long nrand(unsigned long n);
  1134.  
  1135. /* OpenDataFiles.c */
  1136.  
  1137. unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
  1138.                     ,char *inName,char *outName);
  1139.  
  1140. /* OpenPreferencesFolder.c */
  1141.  
  1142. #if !MAC_C
  1143.     #define OSErr short
  1144. #endif
  1145. OSErr OpenPreferencesFolder(void);
  1146. OSErr ClosePreferencesFolder(void);
  1147. OSErr OpenPreferencesWD(short *wdRefNumPtr);
  1148. #if !MAC_C
  1149.     #undef OSErr
  1150. #endif
  1151.  
  1152. #if MAC_C
  1153.     /*    PixMapToPICT.c */
  1154.  
  1155.     void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  1156.         ,int pixelSize,ColorTable **cTable);
  1157.  
  1158.     /*    PixMapToPostScript.c */
  1159.     
  1160.     void WindowToEPS(CWindowPtr window,char *filename,Rect *rectPtr
  1161.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels,float reflectance[256]);
  1162.     void PixMapToEPS(char *filename,PixMap **pm,Rect *rectPtr
  1163.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1164.     void PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
  1165.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1166.     void AppendToFile(char *filename,char *string);
  1167.     
  1168.     /* PlotXY.c */
  1169.     
  1170.     typedef struct{
  1171.         Boolean continuing;    /* zero to start a new curve */
  1172.         long color;            /* e.g. blackColor, blueColor */
  1173.         short lineWidth;    /* in pixels, zero for none */
  1174.         short symbolWidth;    /* in pixels, zero for none */
  1175.         short dashOffset;    /* in pixels */
  1176.         short dash[5];        /* in pixels. The array is terminated by a zero element */
  1177.         short h,v;            /* reserved for internal use */
  1178.         Fixed pathLengthF;    /* reserved for internal use */
  1179.     } PlotXYStyle;
  1180.     void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
  1181. #endif
  1182.  
  1183. /* PrintfExit.c */
  1184.  
  1185. int PrintfExit(const char *format,...);
  1186. int Printf(const char *format,...);
  1187. char *TranslateEOL(char *string);
  1188.  
  1189. #if MAC_C
  1190.     /* PrintfGWorld.c */
  1191.  
  1192.     void PrintfGWorld(GWorldPtr our);
  1193.     void PrintStringAsBitmap(unsigned char *s);
  1194. #endif
  1195.  
  1196. /* PupilMTF.c */
  1197.  
  1198. double PupilMTF(double cPerDeg,double diameterMm,double wavelengthNm);
  1199.  
  1200. #if MAC_C
  1201.     /* QD32Exists.c */
  1202.     
  1203.     Boolean         QD8Exists(void);
  1204.     Boolean            QD32Exists(void);
  1205.     Boolean            NewPaletteManager(void);
  1206. #endif
  1207.  
  1208. /* randU.c */
  1209.  
  1210. unsigned short    randU(void);
  1211. unsigned long    randUL(void);
  1212. void            srandU(unsigned n);
  1213. void            RandFill(void *address,long bytes);
  1214.  
  1215. /* ReadMATLABFile.c */
  1216.  
  1217. int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
  1218.     ,double **real,double **imag);
  1219. int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
  1220.     ,short **real,short **imag);
  1221. int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
  1222.     ,double **real,double **imag);
  1223. int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
  1224.     ,short **real,short **imag);
  1225. int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
  1226. int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
  1227.  
  1228. #if MAC_C
  1229.     /* RectToAddress.c */
  1230.     
  1231.     unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr, 
  1232.         short *pixelSizePtr,short *bitsOffsetPtr);
  1233.     Ptr GetPixBaseAddr32(PixMap **pm);
  1234. #endif
  1235.     
  1236. /*    Require.c    */
  1237.  
  1238. void Require(long quickDrawVersion);
  1239. struct PrecompileSizeofInt{
  1240.     int i;
  1241. };
  1242. struct PrecompileSizeofDouble{
  1243.     double d;
  1244. };
  1245.  
  1246. #if MAC_C
  1247.     /* RestoreCluts.c */
  1248.     
  1249.     void RestoreCluts(void);
  1250.     
  1251.     /* Seconds.c */
  1252.  
  1253.     double Seconds(void);
  1254.     Boolean IsDriverServicesLibAvailable(void);
  1255.  
  1256.     /* SetCrsrState.c */
  1257.  
  1258.     void SetCrsrVis(unsigned char cursorVisible);
  1259.     unsigned char GetCrsrVis(void);
  1260.     short GetCrsrState(void);
  1261.     void SetCrsrState(short val);
  1262.  
  1263.     /*    SetEntriesQuickly.c */
  1264.     
  1265.     OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
  1266.     short macltset(GDHandle device,register short start
  1267.         ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
  1268.     short GetCardType(GDHandle device);
  1269.     char *GetCardBase(GDHandle device);
  1270.     OSErr WaitForNextBlanking(GDHandle device);
  1271.     Boolean SetEntriesQuicklyRecommended(GDHandle device);
  1272.     
  1273.     /* SetFileInfo.c */
  1274.     
  1275.     void    SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
  1276.     
  1277.     /* SetGestaltValue1.c */
  1278.  
  1279.     OSErr SetGestaltValue1(OSType selector,long response);
  1280.  
  1281.     /* SetMouse.c */
  1282.     
  1283.     void    SetMouse(Point where);
  1284.     
  1285.     /* SetOnePixel.c */
  1286.     
  1287.     void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
  1288.     unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
  1289.     unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
  1290.     void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
  1291.     unsigned long GetDevicePixel(GDHandle device,int x,int y);
  1292.     void SetOnePixel(int x,int y,unsigned long value);
  1293.     unsigned long GetOnePixel(int x,int y);
  1294.     #define SetIPixel SetDevicePixel    /*  So that old programs won't break. */
  1295.     #define GetIPixel GetDevicePixel    /*  So that old programs won't break. */
  1296.     
  1297.     /* SetPixelsQuickly.c */
  1298.     
  1299.     int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1300.     int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1301.     int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1302.     int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1303.     int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1304.     int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1305.     int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1306.     int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1307.     
  1308.     /* SetPriority.c */
  1309.     
  1310.     void SwapPriority(char *priority);
  1311.     pascal void SetPriority(long i);
  1312.     pascal long GetPriority(void);
  1313. #endif
  1314.  
  1315. /* Shuffle.c */
  1316.  
  1317. void Shuffle(void *array,long elements,size_t elementSize);
  1318.  
  1319. #if MAC_C
  1320.     /* SndPlay1.c */
  1321.     
  1322.     OSErr SndPlay1(Handle snd);
  1323.     void SndStop1(void);
  1324.     short SndDone1(void);
  1325.  
  1326.     /* StringToDateAndSecs.c */
  1327.     
  1328.     double StringToDateAndSecs(char *string,DateTimeRec *date);
  1329.  
  1330.     /* StringBounds.c */
  1331.     
  1332.     void CharBounds(char a,Rect *bounds,long *count);
  1333.     void StrBounds(char *s,Rect *bounds,long *count);
  1334.     double StrOutlineLength(char *s);
  1335.     void StringBounds(const unsigned char *s,Rect *bounds,long *count);
  1336.     double StringOutlineLength(const unsigned char *s);
  1337.  
  1338.     /* Timer.c */
  1339.     
  1340.     struct Timer{
  1341.         TMTask time;
  1342.         long ourA5;
  1343.         volatile long interval,elapsed,elapsedIntervals;    /* may not need to be volatile */
  1344.         long timeToStartTimer;            /*  minimum time in µs */
  1345.         long stopDelay;                    /*  µs from call to stop, re from call to start */
  1346.         long timeManagerVersion;
  1347.         struct Timer *next,*previous;    /*  doubly linked list of Timers */
  1348.     };
  1349.     typedef struct Timer Timer;
  1350.     
  1351.     Timer *NewTimer(void);
  1352.     void DisposeTimer(Timer *t);
  1353.     void StartTimer(Timer *t);
  1354.     long StopTimer(Timer *t);                    /*  µs */
  1355.     double StopTimerSecs(Timer *t);                /*  s */
  1356.     long PeekTimer(Timer *t);                    /*  µs */
  1357.     double PeekTimerSecs(Timer *t);                /*  s */
  1358.     
  1359.     /* TitleBarHeight.c */
  1360.     
  1361.     int TitleBarHeight(WindowPtr window);
  1362.     
  1363.     /* TrapAvailable.c */
  1364.     
  1365.     Boolean    TrapAvailable(short theTrap);
  1366. #endif
  1367.  
  1368. /* Uniform.c */
  1369.  
  1370. double UniformSample(void);
  1371.  
  1372. #if MAC_C
  1373.     /* VBLInstall.c */
  1374.     
  1375.     #if !UNIVERSAL_HEADERS
  1376.         typedef unsigned long UInt32;
  1377.         struct UnsignedWide {
  1378.             UInt32 hi;
  1379.             UInt32 lo;
  1380.         };
  1381.         typedef struct UnsignedWide UnsignedWide, *UnsignedWidePtr;
  1382.         extern pascal void Microseconds(UnsignedWide *microTickCount)={0xA193, 0x225F, 0x22C8, 0x2280};
  1383.     #endif
  1384.     struct VBLTaskAndA5 {
  1385.         volatile VBLTask vbl;
  1386.         long ourA5;
  1387.         #if USESROUTINEDESCRIPTORS || GENERATINGCFM
  1388.             UniversalProcPtr subroutine;
  1389.         #else
  1390.             void (*subroutine)(struct VBLTaskAndA5 *vblData);
  1391.         #endif
  1392.         GDHandle device;
  1393.         long slot;
  1394.         volatile long newFrame;        /* Boolean */
  1395.         volatile long frame;        /* count up from zero */
  1396.         volatile long framesLeft;    /* count down to zero */
  1397.         long framesDesired;
  1398.         volatile UnsignedWide microTicks;    /* Microseconds() at time of most recent VBL */
  1399.         volatile double seconds;            /* Seconds() at time of most recent VBL */
  1400.         void *ptr;                    /* use this for whatever you want */
  1401.     };
  1402.     typedef struct VBLTaskAndA5 VBLTaskAndA5;    
  1403.     OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,long frames);
  1404.     OSErr VBLRemove(VBLTaskAndA5 *vblData);
  1405.     void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
  1406.     
  1407.     /* VideoTFB.c */
  1408.     
  1409.     Boolean TFBInSlot(int slot);
  1410.     void    SetUpTFB(int slot);
  1411.     void    RampClutTFB(int slot);
  1412.     void    GrayClutTFB(int slot);
  1413.     void    LoadClutTFB(int slot,unsigned char rgb[256][3]);
  1414.     void    NewBlankingTFB(int slot);
  1415.     void    NewFieldTFB(int slot);
  1416.     int        BlankingTFB(int slot);
  1417.     void    SetDepthTFB(int slot,short int bits);
  1418.     void    SynchSetDepthTFB(int masterSlot,int slot,short int bits);
  1419.     void    SynchToMainDeviceTFB(GDHandle device);
  1420.     void    HaltTFB(int slot);
  1421.     void    RestartTFB(int slot,short int bits);
  1422.     void    HaltDeviceTFB(GDHandle device);
  1423.     void    RestartDeviceTFB(GDHandle device);
  1424.     void    ScrollTFB(int slot,short int bits,long x,long y);
  1425.     void    PanTFB(int slot,long int x);
  1426. #endif
  1427.  
  1428. /* VLambda.c */
  1429.  
  1430. double VLambda(double nm);
  1431. double VLambdaPrime(double nm);
  1432.  
  1433. #if MAC_C
  1434.  
  1435.     /* WaitSeconds.c */
  1436.     
  1437.     void WaitSeconds(double secs);
  1438.  
  1439.     /* Zoom.c */
  1440.     
  1441.     void Zoom(WindowPtr theWindow,int zoomDir,EventRecord *event);
  1442. #endif
  1443.  
  1444. #endif /* _VIDEOTOOLBOX_ */
  1445.